<?php
class ModelSettingTooltip extends Model {    
    public function saveTooltip($data) {
        $record = $this->loadTooltip();
        
        if(!isset($data['low_stock_warning'])){
            $data['low_stock_warning'] = 0;
        }
        
        if(!empty($record)){
            $sql = "UPDATE " . DB_PREFIX . "tooltip " .
                " SET " .
                "   low_stock_warning = '" . $this->db->escape($data['low_stock_warning']) . "', " .
                "   low_stock_item = '" . $this->db->escape($data['low_stock_item']) . "', " .
                "   delivery_time_instock = '" . $this->db->escape($data['delivery_time_instock']) . "', " .
                "   delivery_time_outstock = '" . $this->db->escape($data['delivery_time_outstock']) . "', " .
                "   size_hint = '" . $this->db->escape($data['size_hint']) . "', " .
                "   search_hint = '" . $this->db->escape($data['search_hint']) . "', " .
                "   delivery_hint = '" . $this->db->escape($data['delivery_hint']) . "', " .
                "   contact_text = '" . $this->db->escape($data['contact_text']) . "', " .
                "   contact_info = '" . $this->db->escape($data['contact_info']) . "', " .
                "   shipping_note = '" . $this->db->escape($data['shipping_note']) . "', " .
                "   newsletter_text = '" . $this->db->escape($data['newsletter_text']) . "'";                
        }
        else{            
             $sql = "INSERT INTO " . DB_PREFIX . "tooltip " .
                " SET " .
                "   low_stock_warning = '" . $this->db->escape($data['low_stock_warning']) . "', " .
                "   low_stock_item = '" . $this->db->escape($data['low_stock_item']) . "', " .
                "   delivery_time_instock = '" . $this->db->escape($data['delivery_time_instock']) . "', " .
                "   delivery_time_outstock = '" . $this->db->escape($data['delivery_time_outstock']) . "', " .
                "   size_hint = '" . $this->db->escape($data['size_hint']) . "', " .
                "   search_hint = '" . $this->db->escape($data['search_hint']) . "', " .
                "   delivery_hint = '" . $this->db->escape($data['delivery_hint']) . "', " .
                "   contact_text = '" . $this->db->escape($data['contact_text']) . "', " .
                "   contact_info = '" . $this->db->escape($data['contact_info']) . "', " .
                "   shipping_note = '" . $this->db->escape($data['shipping_note']) . "', " .
                "   newsletter_text = '" . $this->db->escape($data['newsletter_text']) . "'";
        }
        $this->db->query($sql);
        
        $this->cache->delete('tooltip');
    }
    
    public function loadTooltip() {      
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "tooltip");
        
        return $query->row;
    }
    
    public function getLowStockItem() {      
        $record = $this->loadTooltip(); 
        
        return $record['low_stock_item'];
    }
    
    public function getDeliveryTimeInstock() {      
        $record = $this->loadTooltip(); 
        
        return $record['delivery_time_instock'];
    }
    
    public function getDeliveryTimeOutstock() {      
        $record = $this->loadTooltip(); 
        
        return $record['delivery_time_outstock'];
    }
}
?>